package com.catmiw.stock2013.domain;

import java.io.*;

public class DayData implements Comparable {
    private int date;
    private float open;
    private float close;
    private float high;
    private float low;
    private float before;

    private int amount;
    private float summoney;
    
    public boolean equals(Object o){
    	return date==((DayData)o).getDate();
    }
    
    public int compareTo(Object o) {
        if (!(o instanceof DayData))
            return 0;
        DayData d = (DayData) o;

        return date - d.date;
    }

    public DayData() {
    }

    public DayData(int date) {
    	this.date=date;
    }

    public DayData(byte[] d) {
        int len = d.length;
        byte[] dc = new byte[len];
        for (int i = 0; i < len; i++) {
            dc[i] = d[len - i - 1];
        }
        try{
            DataInputStream ba = new DataInputStream(new ByteArrayInputStream(
                    dc));
            before=ba.readInt() / 100.0f;
            this.setAmount(ba.readInt());
            this.setSummoney(ba.readFloat());
            this.setClose(ba.readInt() / 100.0f);
            this.setLow(ba.readInt() / 100.0f);
            this.setHigh(ba.readInt() / 100.0f);
            this.setOpen(ba.readInt() / 100.0f);

            int date = ba.readInt();
            this.setDate(date);

        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    public DayData(int date, float open, float close, float high, float low,
                   float before) {
        this.date = date;
        this.open = open;
        this.close = close;
        this.high = high;
        this.low = low;
        this.before = before;
    }

    //�ж��Ƿ�������
    //���ߵĶ��壺���̼۸���ڵ��ڿ��̼۸񣬲��Ҵ��ڵ���ǰ�����̼۸�
    public boolean isRedLine(){
        return close>=open&&close>=before;
        //return close>=open;
    }

    public float getBefore() {
        return before;
    }

    public float getClose() {
        return close;
    }

    public int getDate() {
        return date;
    }

    public float getHigh() {
        return high;
    }

    public float getLow() {
        return low;
    }

    public float getOpen() {
        return open;
    }

    public int getAmount() {
        return amount;
    }

    public float getSummoney() {
        return summoney;
    }

    public void setOpen(float open) {
        this.open = open;
    }

    public void setLow(float low) {
        this.low = low;
    }

    public void setHigh(float high) {
        this.high = high;
    }

    public void setDate(int date) {
        this.date = date;
    }

    public void setClose(float close) {
        this.close = close;
    }

    public void setBefore(float before) {
        this.before = before;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public void setSummoney(float summoney) {
        this.summoney = summoney;
    }

    public String toString() {
        return date + "\t" + open + "\t" + high + "\t" + low + "\t" + close +
                "\t" + before + "\t" + amount + "\t" + summoney;
    }
}
